package cn.edu.sgu.www.mhxysy.controller.chongwu;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.chongwu.ChongwuZizhiDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu.ChongwuZizhi;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.chongwu.ChongwuZizhiService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "宠物资质管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/chongwu_zizhi", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChongwuZizhiController {

	private final ChongwuZizhiService chongwuZizhiService;

	@Autowired
	public ChongwuZizhiController(ChongwuZizhiService chongwuZizhiService) {
		this.chongwuZizhiService = chongwuZizhiService;
	}

	@ApiOperation("通过宠物ID修改宠物资质")
	@RequestMapping(value = "/updateByChongwuId", method = RequestMethod.POST)
	public JsonResult<Void> updateByChongwuId(@Validated ChongwuZizhiDTO chongwuZizhiDTO) {
		chongwuZizhiService.updateByChongwuId(chongwuZizhiDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("通过宠物ID查询宠物资质")
	@RequestMapping(value = "/selectByChongwuId", method = RequestMethod.GET)
	public JsonResult<ChongwuZizhi> selectByChongwuId(
			@ApiParam(name = "chongwuId", value = "宠物ID", required = true)
			@NotBlank(message = CustomMessages.CHONGWU_ID_NOT_NULL) String chongwuId) {
		ChongwuZizhi chongwuZizhi = chongwuZizhiService.selectByChongwuId(chongwuId);

		return JsonResult.success(null, chongwuZizhi);
	}

}